<template>
    <h2>注册</h2>
    <table>
        <tr>
            <td>用户名：</td>
            <td>
                <input type="text" v-model="UserName" />
            </td>
        </tr>
        <tr>
            <td>用户密码：</td>
            <td>
                <input type="password" v-model="Password" />
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <button @click="register">注册</button>
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const UserName = ref('');
const Password = ref('');
const router = useRouter();
const register = () => {
    if (UserName.value == '' || Password.value == '') {
        alert("用户名或密码不能为空");
        return;
    }
    if (Password.value.length < 6 || Password.value.length > 30) {
        alert("用户密码不能少于6位最大不能超过30位")
        return;
    }
    axios.post("http://localhost:50394/api/Regist/AddRegist", {
        UserName: UserName.value,
        Password: Password.value
    })
        .then(res => {
            if (res.data > 0) {
                alert("注册成功");
                router.push('/R_Showlogin');
            }
            else if (res.data == -1) {
                alert("用户已存在");
                return;
            }
            else {
                alert("注册失败");
                return;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
</script>